home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qgcache.h.z / qgcache.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  3.4 KB  |  110 lines

  1. /****************************************************************************
  2. ** $Id: qgcache.h,v 2.4 1998/07/03 00:09:45 hanord Exp $
  3. **
  4. ** Definition of QGCache and QGCacheIterator classes
  5. **
  6. ** Created : 950208
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QGCACHE_H
  25. #define QGCACHE_H
  26.  
  27. #ifndef QT_H
  28. #include "qcollection.h"
  29. #include "qglist.h"
  30. #include "qgdict.h"
  31. #endif // QT_H
  32.  
  33.  
  34. class QCList;                    // internal classes
  35. class QCDict;
  36.  
  37.  
  38. /*****************************************************************************
  39.   QGCache class
  40.  *****************************************************************************/
  41.  
  42. class QGCache : public QCollection        // LRU cache class
  43. {
  44. friend class QGCacheIterator;
  45. protected:
  46.     QGCache( int maxCost, uint size,bool caseS, bool copyKeys, bool trivial );
  47.     QGCache( const QGCache & );            // not allowed, calls fatal()
  48.    ~QGCache();
  49.     QGCache &operator=( const QGCache & );    // not allowed, calls fatal()
  50.  
  51.     uint    count()    const    { return ((QGDict*)dict)->count(); }
  52.     uint    size()    const    { return ((QGDict*)dict)->size(); }
  53.     int        maxCost()    const    { return mCost; }
  54.     int        totalCost() const    { return tCost; }
  55.     void    setMaxCost( int maxCost );
  56.  
  57.     bool    insert( const char *key, GCI, int cost, int priority );
  58.     bool    remove( const char *key );
  59.     GCI        take( const char *key );
  60.     void    clear();
  61.  
  62.     GCI        find( const char *key, bool ref=TRUE ) const;
  63.  
  64.     void    statistics() const;            // output debug statistics
  65.  
  66. private:
  67.     bool    makeRoomFor( int cost, int priority = -1 );
  68.     QCList *lruList;
  69.     QCDict *dict;
  70.     int        mCost;
  71.     int        tCost;
  72.     bool    copyK;
  73. };
  74.  
  75.  
  76. /*****************************************************************************
  77.   QGCacheIterator class
  78.  *****************************************************************************/
  79.  
  80. class QListIteratorM_QCacheItem;
  81.  
  82. class QGCacheIterator                // QGCache iterator
  83. {
  84. protected:
  85.     QGCacheIterator( const QGCache & );
  86.     QGCacheIterator( const QGCacheIterator & );
  87.    ~QGCacheIterator();
  88.     QGCacheIterator &operator=( const QGCacheIterator & );
  89.  
  90.     uint  count()   const;            // number of items in cache
  91.     bool  atFirst() const;            // test if at first item
  92.     bool  atLast()  const;            // test if at last item
  93.     GCI      toFirst();                // move to first item
  94.     GCI      toLast();                // move to last item
  95.  
  96.     GCI      get() const;                // get current item
  97.     const char *getKey() const;            // get current key
  98.     GCI      operator()();                // get current and move to next
  99.     GCI      operator++();                // move to next item (prefix)
  100.     GCI      operator+=( uint );            // move n positions forward
  101.     GCI      operator--();                // move to prev item (prefix)
  102.     GCI      operator-=( uint );            // move n positions backward
  103.  
  104. protected:
  105.     QListIteratorM_QCacheItem *it;        // iterator on cache list
  106. };
  107.  
  108.  
  109. #endif // QGCACHE_H
  110.